<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Google机器学习笔记 - macdfree&#39;s blog</title>
  <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="macd" /><meta name="description" content="Google机器学习笔记" />
<meta name="keywords" content="机器学习" />



<meta name="baidu-site-verification" content="Ak74Sk61bk" />
<meta name="google-site-verification" content="fAeFHpkrhfFS8LxdzXy0EtAPcVStv0faGn238sRF3L8" />


<meta name="generator" content="Hugo 0.54.0" />


<link rel="canonical" href="/posts/ml/google%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" />

<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">




<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>


<link href="/dist/even.min.css?v=3.1.1" rel="stylesheet">
<link href="/lib/fancybox/jquery.fancybox-3.1.20.min.css" rel="stylesheet">




<meta property="og:title" content="Google机器学习笔记" />
<meta property="og:description" content="Google机器学习笔记" />
<meta property="og:type" content="article" />
<meta property="og:url" content="/posts/ml/google%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" />
<meta property="article:published_time" content="2018-03-25T21:41:51&#43;08:00"/>
<meta property="article:modified_time" content="2018-03-25T21:41:51&#43;08:00"/>

<meta itemprop="name" content="Google机器学习笔记">
<meta itemprop="description" content="Google机器学习笔记">


<meta itemprop="datePublished" content="2018-03-25T21:41:51&#43;08:00" />
<meta itemprop="dateModified" content="2018-03-25T21:41:51&#43;08:00" />
<meta itemprop="wordCount" content="1270">



<meta itemprop="keywords" content="" />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Google机器学习笔记"/>
<meta name="twitter:description" content="Google机器学习笔记"/>

<!--[if lte IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
<![endif]-->

<!--[if lt IE 9]>
  <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->

</head>
<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/" class="logo">macdfree&#39;s blog</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <a href="/">
        <li class="mobile-menu-item">首页</li>
      </a><a href="/categories/">
        <li class="mobile-menu-item">分类</li>
      </a><a href="/tags/">
        <li class="mobile-menu-item">标签</li>
      </a><a href="/archive/">
        <li class="mobile-menu-item">归档</li>
      </a>
  </ul>
</nav>
  <div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="/" class="logo">macdfree&#39;s blog</a>
</div>

<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
        <a class="menu-item-link" href="/">首页</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/categories/">分类</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/tags/">标签</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/archive/">归档</a>
      </li>
  </ul>
</nav>
    </header>

    <main id="main" class="main">
      <div class="content-wrapper">
        <div id="content" class="content">
          <article class="post">
    
    <header class="post-header">
      <h1 class="post-title">Google机器学习笔记</h1>

      <div class="post-meta">
        <span class="post-time"> 2018-03-25 </span>
        <div class="post-category">
          
            <a href="/categories/machine-learning/"> machine-learning </a>
          
        </div>
        <span class="more-meta"> 约 1270 字 </span>
        <span class="more-meta"> 预计阅读 3 分钟 </span>
        <span id="busuanzi_container_page_pv" class="more-meta"> <span id="busuanzi_value_page_pv"><img src="/img/spinner.svg" alt="spinner.svg"/></span> 次阅读 </span>
      </div>
    </header>

    
    
<div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  
  <div class="post-toc-content always-active">
    <nav id="TableOfContents">
<ul>
<li><a href="#标签">标签</a></li>
<li><a href="#特征">特征</a></li>
<li><a href="#样本">样本</a>
<ul>
<li><a href="#有标签样本">有标签样本</a></li>
<li><a href="#无标签样本">无标签样本</a></li>
</ul></li>
<li><a href="#模型">模型</a></li>
<li><a href="#回归与分类">回归与分类</a></li>
<li><a href="#线性回归">线性回归</a></li>
<li><a href="#训练与损失">训练与损失</a>
<ul>
<li><a href="#经验风险最小化">经验风险最小化</a></li>
<li><a href="#损失">损失</a></li>
<li><a href="#损失函数">损失函数</a></li>
</ul></li>
<li><a href="#降低损失">降低损失</a>
<ul>
<li><a href="#迭代方法">迭代方法</a></li>
<li><a href="#梯度下降法">梯度下降法</a></li>
<li><a href="#学习速率">学习速率</a></li>
<li><a href="#优化学习速率">优化学习速率</a></li>
<li><a href="#随机梯度下降法-sgd">随机梯度下降法（SGD）</a></li>
</ul></li>
</ul>
</nav>
  </div>
</div>

    
    <div class="post-content">
      <p>最近正在抽空学习Google的<a href="https://developers.google.com/machine-learning/crash-course">《机器学习速成课程》</a>。由于拖延症晚期加上工作忙碌，学习进度缓慢，经常遇到这次看的内容下次就忘了的情况，所以在此记录一下，以加强记忆，巩固所学知识。</p>

<p>监督式机器学习定义：机器学习系统通过学习如何组合输入信息来对从未见过的数据做出有用的预测。</p>

<h1 id="标签">标签</h1>

<p>我们要预测的事物，如小麦未来的价格、图片中显示的动物的品种等，在简单线性回归（$y=b&#43;{ \omega  }_{ 1 }{ x }_{ 1 }&#43;{ \omega  }_{ 2 }{ x }_{ 2 }$）中的<code>y</code></p>

<h1 id="特征">特征</h1>

<p>输入变量，在垃圾邮件检测器示例中，特征可能包含：</p>

<ul>
<li>电子邮件文本中的字词</li>
<li>发件人的地址</li>
<li>发送电子邮件的时段</li>
</ul>

<p>在简单线性回归中的<code>x</code>，对于复杂的机器学习项目，特征会有多个，表示为：</p>

$$\left\{ { x }_{ 1 },{ x }_{ 2 },{ x }_{ 3 },...{ x }_{ n } \right\}$$

<h1 id="样本">样本</h1>

<h2 id="有标签样本">有标签样本</h2>

<p>同时具有特征和标签，用于训练模型。</p>

<h2 id="无标签样本">无标签样本</h2>

<p>只有特征没有标签，用来测试模型。</p>

<h1 id="模型">模型</h1>

<p>表示特征与标签之间的关系。模型生命周期的两个阶段：</p>

<ul>
<li>训练，表示创建或学习模型。向模型展示有标签样本，让模型学习特征与标签之间的关系。</li>
<li>推断，将训练后的模型应用于无标签样本。</li>
</ul>

<h1 id="回归与分类">回归与分类</h1>

<p>回归模型预测连续值，分类模型预测离散值。</p>

<h1 id="线性回归">线性回归</h1>

<p>对于具有三个特征的模型，方程式如下：</p>

$${ y }^{ \prime  }=b&#43;{ \omega  }_{ 1 }{ x }_{ 1 }&#43;{ \omega  }_{ 2 }{ x }_{ 2 }&#43;{ \omega  }_{ 3 }{ x }_{ 3 }$$

<p>其中：</p>

<ul>
<li>${ y }^{ \prime  }$指的是预测的标签</li>
<li>$b$ 指偏差（与y轴的截距）</li>
<li>${ \omega  }_{ 1 }$特征 1 的权重</li>
<li>${ x }_{ 1 }$特征 1（输入项）</li>
</ul>

<h1 id="训练与损失">训练与损失</h1>

<h2 id="经验风险最小化">经验风险最小化</h2>

<p>检查多个样本并尝试找出可最大限度减少损失的模型</p>

<h2 id="损失">损失</h2>

<p>损失是一个<strong>数值</strong>，表示对于<strong>单个</strong>样本而言模型预测的准确程度。</p>

<h2 id="损失函数">损失函数</h2>

<p>常见的损失函数：平方损失（L<sub>2</sub>），单个样本的平方损失如下：</p>

<p>= (observation - prediction(x))<sup>2</sup></p>

<p>= (y - y&rsquo;)<sup>2</sup></p>

<p>即实际值与预测值差值的平方</p>

<p>均方误差（MSE）指的是每个样本的平均平方损失。计算公式为：</p>

$$MSE=\frac { 1 }{ N } \sum _{ (x,y)\in D }^{  }{ (y-prediction(x))^{ 2 } }$$

<p>其中：</p>

<ul>
<li>$(x,y)$指样本，其中

<ul>
<li>$x$表示特征集</li>
<li>$y$表示标签</li>
</ul></li>
<li>$prediction(x)$表示预测模型</li>
<li>$D$表示有标签样本的集合</li>
<li>$N$表示$D$的样本数量</li>
</ul>

<p>类似于方差的计算公式。</p>

<h1 id="降低损失">降低损失</h1>

<h2 id="迭代方法">迭代方法</h2>

<p>迭代方法过程如下图所示：</p>

<p><img src="/images/迭代方法.png" alt="迭代方法" /></p>

<ol>
<li>首先为模型参数设置初始值，并代入特征值得到预测值${ y }^{ \prime  }$。</li>
<li>然后将样本标签和预测值代入损失函数计算损失，并依据此进行参数更新。</li>
<li>最后为模型设置更新后的参数重复上述步骤，直到损失不在变化或变化很慢，则认为已收敛。</li>
</ol>

<h2 id="梯度下降法">梯度下降法</h2>

<p>搞不定，TODO。
只知道一下几点：</p>

<ol>
<li>梯度是一个向量，有方向，有大小；</li>
<li>对于每一个参数都会有一个梯度；</li>
<li>梯度的方向总是指向变化速率大的方向，所以梯度下降算法需要用负梯度；</li>
<li>参数值向负梯度的方向移动一段距离，通常为梯度的值乘以某个数值得到；</li>
<li>通过不断计算梯度，移动距离可到达损失最小的点。</li>
</ol>

<h2 id="学习速率">学习速率</h2>

<p>即上一节中第四点中提到的<strong>某个数值</strong>，例如梯度大小为2.5，学习速率为0.01，则梯度下降算法移动的距离为0.025。</p>

<p>学习速率就是一个<strong>超参数</strong>。</p>

<h2 id="优化学习速率">优化学习速率</h2>

<p>太小浪费时间，太大会错过最低点。</p>

<h2 id="随机梯度下降法-sgd">随机梯度下降法（SGD）</h2>

<p>针对单次迭代，只使用一个样本，就叫随机梯度下降法。</p>

<p>针对单次迭代，使用一小批样本（10-1000），就叫小批量随机梯度下降法（小批量SGD）。</p>
    </div>

    
    <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">macd</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">2018-03-25</span>
  </p>
  
  
</div>

    
    
<div class="post-reward">
  <input type="checkbox" name="reward" id="reward" hidden />
  <label class="reward-button" for="reward">赞赏支持</label>
  <div class="qr-code">
    
    
      <label class="qr-code-image" for="reward">
        <img class="image" src="/img/reward/wechat-qr-code.png">
        <span>微信打赏</span>
      </label>
    
      <label class="qr-code-image" for="reward">
        <img class="image" src="/img/reward/alipay-qr-code.png">
        <span>支付宝打赏</span>
      </label>
  </div>
</div>

    <footer class="post-footer">
      

      
      <nav class="post-nav">
        
          <a class="prev" href="/posts/dotnet%E4%B8%ADpasswordderivebytes.cryptderivekey%E7%9A%84java%E5%AE%9E%E7%8E%B0/">
            <i class="iconfont icon-left"></i>
            <span class="prev-text nav-default">.NET中PasswordDeriveBytes.CryptDeriveKey的Java实现</span>
            <span class="prev-text nav-mobile">上一篇</span>
          </a>
        
          <a class="next" href="/posts/axis%E8%B0%83%E7%94%A8cxf%E5%8F%91%E5%B8%83%E7%9A%84webservice%E9%81%87%E5%88%B0%E7%9A%84%E9%97%AE%E9%A2%98/">
            <span class="next-text nav-default">Axis调用CXF发布的WebService遇到的问题</span>
            <span class="prev-text nav-mobile">下一篇</span>
            <i class="iconfont icon-right"></i>
          </a>
      </nav>
    </footer>
  </article>
        </div>
        
  <div id="comments-gitment"></div>
  <link rel="stylesheet" href="/lib/gitment/gitment-0.0.3.min.css">
    <script src="/lib/gitment/gitment-0.0.3.min.js"></script>
  <script type="text/javascript">
  const gitment = new Gitment({
    id: '2018-03-25 21:41:51 \x2b0800 \x2b0800',
    title: 'Google机器学习笔记',
    link: decodeURI(location.href),
    desc: '\x3cp\x3e最近正在抽空学习Google的\x3ca href=\x22https:\/\/developers.google.com\/machine-learning\/crash-course\x22\x3e《机器学习速成课程》\x3c\/a\x3e。由于拖延症晚期加上工作忙碌，学习进度缓慢，经常遇到这次看的内容下次就忘了的情况，所以在此记录一下，以加强记忆，巩固所学知识。\x3c\/p\x3e',
    owner: 'MACDfree',
    repo: 'gitment4',
    oauth: {
      client_id: '3de7eda9fae832753b25',
      client_secret: 'fb1c82c44491295195db0eb7a2d12af22dfcae29'
    }
  })
  gitment.render('comments-gitment')
  </script>
  <noscript>Please enable JavaScript to view the <a href="https://github.com/imsun/gitment">comments powered by gitment.</a></noscript>
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="social-links">
      <a href="mailto:macdfree@163.com" class="iconfont icon-email" title="email"></a>
      <a href="https://github.com/MACDfree" class="iconfont icon-github" title="github"></a>
  <a href="/index.xml" type="application/rss+xml" class="iconfont icon-rss" title="rss"></a>
</div>

<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://gohugo.io">Hugo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 - 
    <a class="theme-link" href="https://github.com/olOwOlo/hugo-theme-even">Even</a>
  </span>

  <div class="busuanzi-footer">
    <span id="busuanzi_container_site_pv"> 本站总访问量 <span id="busuanzi_value_site_pv"><img src="/img/spinner.svg" alt="spinner.svg"/></span> 次 </span>
    <span class="division">|</span>
    <span id="busuanzi_container_site_uv"> 本站总访客数 <span id="busuanzi_value_site_uv"><img src="/img/spinner.svg" alt="spinner.svg"/></span> 人 </span>
  </div>

  <span class="copyright-year">
    &copy; 
    
      2014 - 
    2019
    <span class="heart">
      <i class="iconfont icon-heart"></i>
    </span>
    <span class="author">macd</span>
    <span class="division">|</span>
    <span style="margin-left: 5px;">
      <img alt="buildstatus" src="https://travis-ci.org/MACDfree/hugoblog.svg?branch=master">
    </span>
  </span>
</div>
    </footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont icon-up"></i>
    </div>
  </div>
  
<script src="/lib/highlight/highlight.pack.js?v=20171001"></script><script type="text/javascript" src="/lib/jquery/jquery-3.2.1.min.js"></script>
  <script type="text/javascript" src="/lib/slideout/slideout-1.0.1.min.js"></script>
  <script type="text/javascript" src="/lib/fancybox/jquery.fancybox-3.1.20.min.js"></script>
<script type="text/javascript" src="/dist/even.min.js?v=3.1.1"></script>
  <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]},
      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
      displayMath: [['$$','$$'], ['\[','\]']],
      processEscapes: true,
      processEnvironments: true
    });
  </script>
  <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/MathJax.js?config=TeX-MML-AM_CHTML"></script>








</body>
</html>
